Ext.define('component.marketing.haveReceive', {
	extend : 'Ext.form.Panel',
	config:{ 
		receivablesType: ''
	},
	initComponent:function(){
		var receivablesType=this.receivablesType;
		//房款类型
	    var typeHave = [
	         {"value":"","text":"请选择"},
	         {"value":"1","text":"认筹金"},
	         {"value":"3","text":"认购金"},
	         {"value":"5","text":"一次性全款"},
	         {"value":"6","text":"商业贷款-首付款"},
	         {"value":"7","text":"商业贷款-按揭款"},
	         {"value":"10","text":"公积金-首付款"},
	         {"value":"11","text":"公积金-按揭款"},
	         {"value":"12","text":"分期-一期款"},
	         {"value":"13","text":"分期-二期款"},
	         {"value":"14","text":"分期-三期款"},
	         {"value":"15","text":"分期-四期款"},
	         {"value":"16","text":"分期-五期款"},
	         {"value":"17","text":"组合贷款-首付款"},
	         {"value":"18","text":"组合贷款-银行按揭"},
	         {"value":"19","text":"组合贷款-公积金按揭"},
	         {"value":"20","text":"签约金"},
	         {"value":"23","text":"补差款"}
	    ];
	    var relationTypeHave = Ext.data.Store({
	    	autoDestroy: true,
	        fields :["value","text"],
	        data : typeHave
	    });
	    
//		var formHave = Ext.create("Ext.form.Panel", {
//			//minHeight:170,
//		    title: "查询条件",
//		    collapsible: true,  //可折叠
//		    autoScroll: false,   //自动创建滚动条
//		    defaultType: 'textfield',
//		    defaults: {
//		    	 anchor: '100%',
//		    },
//		    fieldDefaults: {
//		        margin: 2
//		    },
//		    items: [{
//		            xtype: "container",
//		            layout: "hbox",
//		            items: [
//		                { xtype: "hiddenfield", name: "relationId", value: relationId},
//		                { xtype: "textfield", name: "billCode", fieldLabel: "票据单号", labelAlign:'right', labelWidth:100},
//		                {
//				            xtype: "container",
//				            layout: "hbox",
//				            items: [
//		            	        {
//					            	xtype:'container',
//					            	layout:'hbox',
//					            	items:[{
//					            		xtype:'datefield',
//						                fieldLabel:'结算日期',
//						                name:'jsDateStart',
//						                format: 'Y-m-d',
//							              labelAlign:'right',
//							              labelWidth:100
//
//					            	},{
//					            		xtype:'datefield',
//					            		fieldLabel:'',
//					            		name:'jsDateEnd',
//							            labelAlign:'right',
//							            format: 'Y-m-d',
//							            labelWidth:100
//					            	}]
//					                
//					            }
//		            	        
//				            ]
//			            },{  
//		                  xtype:'combobox',
//		 		    	  fieldLabel:'房款类型',
//		 		    	  store:relationTypeHave,
//		 		    	  displayField: "text",
//		 		    	  valueField:"value",
//		 		    	  id:'housingFundType',
//		 		    	  name:'housingFundType',
//		 		    	  labelAlign:'right', 
//		 		    	  labelWidth:100
//	        	        }
//		            ]
//	            }
//		        ],
//		    buttons: [
//	  	        { xtype: "button", text: "查询", 
//	  	          handler:function(){
//	  	        	  gridStoreHave.load();
//	  	          }  
//	  	        },
//	  	        { xtype: "button", text: "清空",handler:function(){
//	  	        	  formHave.getForm().reset();
//	  	          }
//	  	        },{ xtype: "button", text: "返回",handler:function(){
//	  	        	  history.go(-1);
//	  	          }
//	  	        }
//	  	    ]    
//	});
	
	var gridStoreHave = Ext.create('Ext.data.Store', {
        fields: ["relationId", "relationCode", "receivablesType", "customer_name", "combined_name", "relationType", "businessType", "billCode", 
                 "realAmount", "statementDate", "statement_name", "paymentMethod_name", "remark", "reChecked"],
        pageSize: 10,  //页容量15条数据
        //是否在服务端排序 （true的话，在客户端就不能排序）
        remoteSort: false,
        proxy: {
            type: 'ajax',
            url: jypath+'/marketing/haveReceiveRefund/re_checked_list?relationId='+relationId+"&receivablesType="+receivablesType+"&needAuth=F",
            actionMethods: { read: 'POST' },
            reader: {   //这里的reader为数据存储组织的地方，下面的配置是为json格式的数据，例如：[{"total":50,"rows":[{"a":"3","b":"4"}]}]
                type: 'json', //返回数据类型为json格式
                root: 'rows',  //数据
                totalProperty: 'total' //数据总条数
            }
        },
        autoLoad: true  //即时加载数据
    });
	
//	gridStoreHave.on("beforeload",function(){
//        Ext.apply(gridStoreHave.proxy.extraParams,formHave.getForm().getValues());
//    });
	
	var gridHave = Ext.create('Ext.grid.Panel', {
		minHeight:300,
		minWidth:300,
        store: gridStoreHave,
        columnLines: true,
        columns: [{
            text     : '业务编号', 
            dataIndex: 'relation',
            renderer : function(value,cellmeta,record,rowIndex,columnIndex,store) {
            	var rec = gridHave.getStore().getAt(rowIndex);
            	var html = "";
            	if(rec.get('receivablesType') == "0"){
            		//认筹
            		url = jypath+"/customer/payDeposit/toView?id="+rec.get('relationId')+"&returnUrl="+returnBackParam;
            	}else if(rec.get('receivablesType') == "1"){
            		//认购
	                html+= "<a href='javascript:parent.openMenu(\"0\",\""+rec.get('relationId')+"\",\"\",\"认购详情\",\"/customer/subscribe/toView?id="+rec.get('relationId')+"&returnUrl=,marketing,pin,index\")' style='cursor:pointer'>"+rec.get('relationCode')+"</a>"
            	}else if(rec.get('receivablesType') == "2"){
            		//签约
            		 var tabKey = "sig_"+rec.get('relationId');
                     var html = "<a href='javascript:parent.openMenu(\"0\",\""+tabKey+"\",\"\",\"签约详情\",\"/customer/signed/toView?id="+rec.get('relationId')+"&returnUrl=,marketing,pin,index\")' style='cursor:pointer'>"+rec.get('relationCode')+"</a>";
            	}else if(rec.get('receivablesType') == "3"){
            		//面积补差
            		url = jypath+"/marketing/reserveArea/reserveAreaDetail?id="+rec.get('relationId')+"&returnUrl="+returnBackParam;
            	}
	        
	        	return html;
	        }
        },{
            text     : '客户名称', 
            dataIndex: 'customer_name'
        },{
            text     : '房号',
            dataIndex: 'combined_name',
            width:150
        },{
            text     : '房款类型',
            dataIndex: 'relationType'
        },{
            text     : '业务标志',
            dataIndex: 'businessType'
        },{
            text     : '发生额',
            dataIndex: 'realAmount'
        },{
            text     : '票据号码',
            dataIndex: 'billCode'
        },{
            text     : '结算日期',
            dataIndex: 'statementDate',
            renderer : function(val) {
            	return dateFormat(val);
            }
        },{
            text     : '结算人员',
            dataIndex: 'statement_name'
        },{
            text     : '结算方式',
            dataIndex: 'paymentMethod_name'
        },{
            text     : '备注',
            dataIndex: 'remark'
        },{  
            text : "操作",  
            dataIndex: 'actioncolumn',
            renderer : function(value,cellmeta,record,rowIndex,columnIndex,store) {
            	var rec = gridHave.getStore().getAt(rowIndex);
            	var html = "";
                //冲销
            	if(rec.get('reChecked') != "1"){
            		html = '<a onclick="chongxiao('+rec.get('id')+')" style="cursor:pointer">冲销</a>';
            	}
	        	
	        	return html;
            }
        }],
        title: '已收款明细',
        dockedItems: [{  
            xtype: 'pagingtoolbar',  
            store: gridStoreHave,   // GridPanel中使用的数据  
            dock: 'bottom',  
            displayInfo: true,  
            emptyMsg:"没有数据",  
            displayMsg:"显示从{0}条数据到{1}条数据，共{2}条数据"
        }
        ]
    });
	
		
		var defaultConfigHave = {
				defaults: {  
		            split: true,    //有分割线  
		            collapsible: true,  //可以折叠
		        },
				items:[gridHave],
				dockedItems: [{
		            xtype: 'toolbar',
		            dock: 'bottom',
		            ui: 'footer',
		            layout: {
		                pack: 'left'
		            },
		            items: [{
		                minWidth: 80,
		                text: '返回',
		                handler: back
		            }]
		      }]
		};
		Ext.apply(this,defaultConfigHave);
		this.callParent(arguments);
	}
});

function back(){
	 var tabKey = "have_"+relationId;
	 parent.TabControlRemove(tabKey);
}

function chongxiao(id){
	Ext.MessageBox.confirm("提示","请确认是否冲销？",function(btn,txt){
    	if(btn=="yes"){
    		Ext.Ajax.request({
    			 url: jypath+'/marketing/haveReceiveRefund/edit',
                 params: { "id": id, "delFlag":"1"},
                 method: 'POST',
                 callback: function (options, success, response) {
                	 if (success) {
                		 Ext.MessageBox.alert("系统提示","冲销成功");
                		 location.href = jypath + "/marketing/pin/haveReceive?relationId="+relationId;
                	 }else{
                		 Ext.MessageBox.alert("系统提示","冲销失败");
                	 }
                 }
    		});
        }
    });
}

function dateFormat(value){ 
    if(null != value){ 
        return Ext.Date.format(new Date(value),'Y-m-d'); 
    }else{ 
        return null; 
    } 
} 
